package demo4;


abstract class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public abstract void eat();

    /*public void fly(){}
    //不建议在抽象类中写，不是所有动物都会飞，会跑，会游泳的
    public void run() {}
    public void swim() {}*/
}


interface IFly {
    void fly();
}
interface IRun {
    void run();
}
interface ISwim {
    void swim();
}


class Dog extends Animal implements IRun {

    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + " 正在吃狗粮！");
    }

    @Override
    public void run() {
        System.out.println(this.name + " 四条腿猛猛跑！");

    }
}

class Frog extends Animal implements IRun, ISwim {

    public Frog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + " 正在吃蛙粮！");
    }

    @Override
    public void run() {
        System.out.println(this.name + " 两条腿跳着跑！");
    }

    @Override
    public void swim() {
        System.out.println(this.name + " 蛙泳唰唰游！");
    }
}

class Duck extends Animal implements IRun, ISwim, IFly {

    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + " 正在吃鸭粮！");
    }

    @Override
    public void fly() {
        System.out.println(this.name + " 酷酷飞！");
    }

    @Override
    public void run() {
        System.out.println(this.name + " 两条腿迈着跑！");
    }

    @Override
    public void swim() {
        System.out.println(this.name + " 滑着游泳！");
    }
}

class Robot implements IRun {
    public String name;

    public Robot(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(this.name + "机器人会跑！");
    }
}




public class Test {

    public static void func1(Animal animal) {
        animal.eat();
    }

    public static void running (IRun iRun) {
        iRun.run();
    }

    public static void swimming (ISwim iSwim) {
        iSwim.swim();
    }

    public static void flying (IFly iFly) {
        iFly.fly();
    }


    public static void main(String[] args) {
        func1(new Dog("六六", 3));
        func1(new Frog("蛙蛙", 2));
        func1(new Duck("唐老鸭", 5));

        System.out.println("=========================");
        running(new Dog("六六", 3));
        running(new Frog("蛙蛙", 2));
        running(new Duck("唐老鸭", 5));
        running(new Robot("大黄蜂"));

        System.out.println("=========================");
        swimming(new Frog("蛙蛙", 2));
        swimming(new Duck("唐老鸭", 5));


        System.out.println("=========================");

        flying(new Duck("唐老鸭", 5));


       /* Dog dog = new Dog("六六", 3);
        System.out.println(dog.name);
        System.out.println(dog.age);
        dog.run();
        dog.swim();

        System.out.println("============================");


        Frog frog = new Frog("蛙蛙",2);
        System.out.println(frog.name);
        System.out.println(frog.age);
        frog.run();
        frog.swim();

        System.out.println("============================");

        Duck duck = new Duck("大鹏", 5);
        System.out.println(duck.name);
        System.out.println(duck.age);
        duck.fly();
        duck.run();
        duck.swim();*/
    }
}
